﻿using Nop.Core.Domain.Logistics;
using System.Data.Entity.ModelConfiguration;

namespace Nop.Data.Mapping.Logistics
{
    public partial class LocationMap : EntityTypeConfiguration<LogisticsLocation>
    {
        public LocationMap()
        {
            this.ToTable("LogisticsLocation");

            this.Property(l => l.CreatedOnUtc).IsRequired();
            this.Property(l => l.UpdatedOnUtc).IsOptional();
            this.Property(l => l.Rank).IsOptional();
            this.Property(l => l.Status).IsRequired();
            this.Property(l => l.PackageId).IsOptional();

            this.Ignore(l => l.RelatedLocation);
            //this.Ignore(l => l.RelatedPackageStatus);

            this.HasRequired(l => l.Address)
                .WithMany()
                .HasForeignKey(l => l.AddressId)
                .WillCascadeOnDelete(false);
            this.HasOptional(l => l.Plan)
                .WithMany(p => p.AssignedLocations)
                .HasForeignKey(l => l.PlanId)
                .WillCascadeOnDelete(false);
            this.HasOptional(l => l.Courier)
                .WithMany()
                .HasForeignKey(l => l.CourierId)
                .WillCascadeOnDelete(false);
            this.HasRequired(l => l.Package)
                .WithMany()
                .HasForeignKey(l => l.PackageId)
                .WillCascadeOnDelete(false);
            this.HasOptional(l => l.District)
                .WithMany()
                .HasForeignKey(l => l.DistrictId)
                .WillCascadeOnDelete(false);
        }
    }
}
